//
// Created by Administrator on 2024/1/27.
//
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
#include <unordered_map>
using namespace std;

class Solution
{
public:
    vector<int> maxSubsequence(vector<int>& nums, int k)
    {
        unordered_map<int, int> map;
        vector<int> ret, t(nums);
        // 排序
        sort(t.begin(), t.end(), greater<>());
        // 默认从小到达排，最大的在后面
        for (auto n : t)
        {
            if (k > 0)
            {
                k--;
                map[n]++; // 标记
            }
        }
        for (auto x : nums)
        {
            if (map[x])
            {
                --map[x];
                ret.push_back(x);
            }
        }
        return ret;
    }
};

int main()
{
    Solution solution;
    vector<int> nums{-1,-2,3,4};
    auto ans = solution.maxSubsequence(nums, 3);
    for (auto n : ans)
    {
        cout << n << " " << endl;
    }
}
